﻿// CSplashDlg.cpp: 实现文件
//

#include "pch.h"
#include "HotelManagementMFC.h"
#include "afxdialogex.h"
#include "CSplashDlg.h"


// CSplashDlg 对话框

IMPLEMENT_DYNAMIC(CSplashDlg, CDialog)

CSplashDlg::CSplashDlg(CWnd* pParent /*=nullptr*/)
	: CDialog(IDD_SPLASHDLG, pParent)
{

}

CSplashDlg::~CSplashDlg()
{
}

void CSplashDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSplashDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_CTLCOLOR()
END_MESSAGE_MAP()


// CSplashDlg 消息处理程序


BOOL CSplashDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	LOGFONT LogFont;
	GetFont()->GetLogFont(&LogFont);
	LogFont.lfHeight += LogFont.lfHeight / 2;
	LogFont.lfWidth += LogFont.lfWidth / 2;
	LogFont.lfWeight = FW_THIN;
	LogFont.lfCharSet = ANSI_CHARSET;
	LogFont.lfQuality = CLEARTYPE_QUALITY;
	LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_MODERN;
	lstrcpy(LogFont.lfFaceName, L"黑体");
	m_font1.CreateFontIndirectW(&LogFont);
	m_font2.CreateFontIndirectW(&LogFont);

	GetDlgItem(IDC_STATIC_TITLE)->SetFont(&m_font1);
	GetDlgItem(IDC_STATIC_NAME)->SetFont(&m_font2);

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}


void CSplashDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	// 获取窗体大小
	CRect rect;
	GetClientRect(&rect);
	CDC dcMem;
	dcMem.CreateCompatibleDC(&dc);
	// 加载背景图片
	CBitmap bmpBackground;
	bmpBackground.LoadBitmapW(IDB_BITMAP_SYSTEM);
	BITMAP bitMap;
	bmpBackground.GetBitmap(&bitMap);
	CBitmap* pbmpOld = dcMem.SelectObject(&bmpBackground);
	dc.StretchBlt(
		0,
		0,
		rect.Width(),
		rect.Height(),
		&dcMem,
		0,
		0,
		bitMap.bmWidth,
		bitMap.bmHeight,
		SRCCOPY);
	dcMem.SelectObject(pbmpOld);
	dcMem.DeleteDC();

	// 不为绘图消息调用 CDialog::OnPaint()
}


HBRUSH CSplashDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	switch (nCtlColor)
	{
	case CTLCOLOR_STATIC:
	{
		// 设置为透明
		pDC->SetBkMode(TRANSPARENT);
		// 设置字体颜色为红色
		pDC->SetTextColor(RGB(0, 0, 0));
		hbr = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
		break;
	}
	}

	// TODO:  如果默认的不是所需画笔，则返回另一个画笔
	return hbr;
}
